﻿using System;
using System.IO;
using System.Xml;
using YArchitech.LIB;

namespace YArchitech.HVAC
{
	public class DataReadWrite
	{
		public static void InitializeFilePath(string path)
		{
			if (!File.Exists(path))
			{
				if (File.Exists(Path.Combine(Product.DataLocation, "User\\HYAirSystemSetting.xml")))
				{
					File.Copy(Path.Combine(Product.DataLocation, "User\\HYAirSystemSetting.xml"), path);
					return;
				}
				XmlDocument xmlDocument = new XmlDocument();
				XmlDeclaration newChild = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null);
				xmlDocument.AppendChild(newChild);
			}
		}

		public static void WriteValue(string xmlPath, string parentName, string subName, string value)
		{
			XMLOperating.EditNodeText(xmlPath, parentName, subName, value);
		}

		public static string ReadValue(string xmlPath, string parentName, string subName)
		{
			return XMLOperating.GetNodeText(XMLOperating.LoadXml(xmlPath), parentName, subName);
		}
	}
}
